package com.smartmedical.doctor.interrogation.service.impl;

import com.github.pagehelper.PageHelper;
import com.smartmedical.common.core.constant.TokenConstants;
import com.smartmedical.common.core.domain.HealthR;
import com.smartmedical.common.security.service.TokenService;
import com.smartmedical.common.security.utils.SecurityUtils;
import com.smartmedical.doctor.interrogation.mapper.InterrogationMapper;
import com.smartmedical.doctor.interrogation.pojo.entity.InquiryRecordEntity;
import com.smartmedical.doctor.interrogation.pojo.vo.*;
import com.smartmedical.doctor.interrogation.service.InterrogationService;
import com.smartmedical.system.api.domain.Doctor;
import com.smartmedical.system.api.model.LoginUser;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import java.util.Date;
import java.util.List;

/**
 * @Author：闫晓琪
 * @Filename：InterrogationServiceImpl
 * @Package：com.smartmedical.doctor.interrogation.service.impl
 * @Project：smart-medical
 * @name：InterrogationServiceImpl
 * @Date：2024/1/10 19:47
 */

@Service
@Slf4j
public class InterrogationServiceImpl implements InterrogationService {

   @Autowired
   private InterrogationMapper interactionMapper;
    @Autowired
    private HttpServletRequest request;
    @Autowired
    private TokenService tokenService;




    @Override
    public EchoUserVo findUserInfo(Integer userId) {
        return interactionMapper.findUserInfo(userId);
    }

    @Override
    public Integer endInquiry(Integer recordId) {
        return interactionMapper.endInquiry(recordId);
    }

    @Override
    public List<DoctorHistoryInquiryRecordVo> findHistoryInquiryRecord() {
        return interactionMapper.findHistoryInquiryRecord();

    }


    @Override
    public List<InquiryChatRecordVo> findInquiryDetailsList(Integer recordId) {
        return interactionMapper.findInquiryDetailsList(recordId);
    }

    @Override
    public List<DoctorHistoryInquiryRecordVo> list() {
        return interactionMapper.list();
    }

    @Override
    public List<InquiryEvaluateMessage> findDoctorEvaluate(Integer recordId) {
        return interactionMapper.findDoctorEvaluate(recordId);
    }

    @Override
    public HealthR pushMessage1(Integer inquiryId, String content, Integer type, Integer userId) {
        LoginUser loginUser = SecurityUtils.getLoginUser();
        Long id = loginUser.getUserid();

        int isDoc=1;
        int noDoc=0;
        Date date = new Date();
        Integer healthR = interactionMapper.pushMessage1(id, content, type, userId, isDoc, noDoc, date, inquiryId);
        if (healthR>0){
            return HealthR.ok("发送成功");
        }
        return HealthR.fail("发送失败");
    }




    private LoginUser getLogiUser() {
        String header = request.getHeader(TokenConstants.SESSION_ID);
        LoginUser loginUser = tokenService.getLoginUser(header);
        return loginUser;
    }
}
